package com.kude.service;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.SimpleExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.kude.manager.OperException;
import com.kude.manager.ProductCategoryPrefixManager;
import com.kude.util.BeanFactory;
import com.kude.entity.ProductCategoryPrefix;

public class ProductCategoryPrefixService {
	private static final Logger logger = LoggerFactory
			.getLogger(ProductCategoryPrefixService.class.getName());

	private ProductCategoryPrefixManager productCategoryPrefixManager;

	/**
	 * 获取指定ID的产品前缀
	 * 
	 * @param id
	 * @return ProductCategoryPrefix
	 * @throws OperException
	 */
	public ProductCategoryPrefix getProductCategoryPrefixById(int id)
			throws OperException {
		return productCategoryPrefixManager.get(id);
	}

	/**
	 * 增加第一层产品类别
	 * 
	 * @param articleCategoryPrefix
	 * @return
	 * @throws OperException
	 */
	public boolean addProductCategoryPrefix(
			ProductCategoryPrefix productCategoryPrefix) throws OperException {
		// TODO 保证prefix的唯一
		productCategoryPrefixManager.add(productCategoryPrefix);
		return true;

	}

	/**
	 * 更新第一层产品类别的属性
	 * 
	 * @param articleCategoryPrefix
	 * @throws OperException
	 */
	public void updateProductCategoryPrefix(
			ProductCategoryPrefix productCategoryPrefix) throws OperException {
		productCategoryPrefixManager.update(productCategoryPrefix);
	}

	/**
	 * 删除第一层产品类别
	 * 
	 * @param id
	 * @throws OperException
	 */
	public void deleteProductCategoryPrefix(int id) throws OperException {
		// TODO 外键限制，先提示清空所属类别后再进行删除
		productCategoryPrefixManager.delete(id);
	}

	/**
	 * 取得所有第一层产品类别
	 * @return 
	 * @throws OperException 
	 */
	public List findAll() throws OperException{
		System.out.println(productCategoryPrefixManager+"11111111111111");
		return productCategoryPrefixManager.find(Restrictions.isNotNull("prefixId"));
	}
	
	/**
	 * 根据前缀取得第一层的类别
	 * @throws OperException 
	 */
	public List findByPrefixName(Object productProfixName) throws OperException {
		return productCategoryPrefixManager.find(Restrictions.like("productProfixName", productProfixName+"%",MatchMode.ANYWHERE));
	}
	public void setProductCategoryPrefixManager(
			ProductCategoryPrefixManager productCategoryPrefixManager) {
		this.productCategoryPrefixManager = productCategoryPrefixManager;
	}
	
	
}
